package com.zyg.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zyg.dao.PositionMapper;
import com.zyg.dao.PositionMapper;
import com.zyg.pojo.Position;
import com.zyg.pojo.Position;
import com.zyg.service.PositionService;
import org.springframework.stereotype.Service;

@Service
public class PositionServiceImpl extends ServiceImpl<PositionMapper, Position> implements PositionService {
    private final PositionMapper positionMapper;

    public PositionServiceImpl(PositionMapper positionMapper) {
        this.positionMapper = positionMapper;
    }

    @Override
    public Page<Position> getPositionPage(int pageNum, int pageSize, String name, String identificationNumber) {
        QueryWrapper<Position> queryWrapper = new QueryWrapper<>();

        // 动态添加查询条件
        if (name != null && !name.isEmpty()) {
            queryWrapper.like("name", name);
        }
        if (identificationNumber != null && !identificationNumber.isEmpty()) {
            queryWrapper.like("identification_number", identificationNumber);
        }

        // 分页查询
        Page<Position> page = new Page<>(pageNum, pageSize);
        return positionMapper.selectPage(page, queryWrapper);
    }
}
